<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加公告</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/jedate.css">
    <link rel="stylesheet" href="../css/index.css" type="text/css">
    <script src="../js/lib/jquery.min.js?v=20170408"></script>
    <script src="../js/common.js?v=20170408"></script>
    <script src="../js/lib/jquery.cookie.js?v=20170408"></script>
    <script src="../js/lib/bootstrap.min.js?v=20170408"></script>
    <script src="../js/jeDate/jquery.jedate.min.js?v=20170408"></script>
    <script src="../js/lib/jquery.validate.min.js?v=20170408"></script>
    <script src="../js/lib/bootstrap-paginator.min.js?v=20170408"></script>
    <script src="../js/lib/jsrender.js?v=20170408"></script>
    <script src="../js/main.js?v=20170408"></script>

    <script>
        //公告实体
        var notice;
        function init(noticetable){
            notice = noticetable;
            disableInput();
            //[start]设置表单提交
            initDate();
            $("#title").val(noticetable.title);
            $("#content").val(noticetable.content);
            $("#start_dt").val(noticetable.startTime);
            $("#end_dt").val(noticetable.endTime);
            if(noticetable.type == 1){
                $("#xt").attr("checked","checked");
            }else{
                $("#pmd").attr("checked","checked");
            }
            $("#save_btn").click(function () {
                var title = $("#title").val();
                if(title == ""){
                    common.lightBox.showMessage("请输入公告标题");
                    return ;
                }
                var content = $("#content").val();
                if(content == ""){
                    common.lightBox.showMessage("请输入公告内容");
                    return ;
                }
                var type = $('input[name="noticetable_type"]:checked').val();
                notice.title = title;
                notice.content = content;
                notice.startTime = $("#start_dt").val();
                notice.endTime = $("#end_dt").val();
                notice.type = type;
                $.ajax({//添加cookie
                    url:  majiangurl + "noticetable/" +
                        (notice.id ? "editNoticetable" : "createNoticetable"),
                    type:"post",
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain: true,
                    dataType: "json",
                    data:{
                        "str" : JSON.stringify(notice)
                    },
                    success: function (data) {
                        if (data.status != 200) {
                            common.lightBox.showMessage(data.message);
                        } else {
                            common.lightBox.showMessage('编辑成功');
                            history.back();
                            //window.location.href="index.html?path=/discount";
                        }
                    }
                });

            });
            //[end]
        }

        //禁用编辑框
        $(document).ready(function() {
            disableInput();
        });
        function disableInput() {
            var enable = $.getUrlParam('enable');
            var noticetableId = $.getUrlParam('noticetableId');
            if (enable == "false") {
                $("#save_btn").hide();
                $("input[type=text]").attr('readonly',"");
                $("input[type=radio]").attr('disabled',"");
                $('.form_datetime').attr('disabled',"");
                $('#content').attr("disabled","");
                $("#start_dt").attr("disabled","");
                $("#end_dt").attr("disabled","");

            }
            if(noticetableId == undefined){
            }
        };

        var noticeId  = $.getUrlParam('noticetableId');
        if(noticeId)
            $.getRequest(majiangurl + "noticetable/getNoticetable", { str:
                        "{" +
                            "\"id\": \"" + noticeId + "\"" +
                        "}"},
                    function(data){
                        if(data.status == "200"){
                            //[start]设置商品列表
                            var noticetable =  data.result;
                            init(noticetable);
                        }

                    });
        else{
            $(document).ready(function () {
                init({
                    "title": "",
                    "content": "",
                    "type": "100"

                });
            })
        }
    </script>
</head>
<body>
<!--内容-->
<div class="container-fluid">
    <ol class="breadcrumb">
        <li>公告管理</li>
        <li>公告编辑</li>
    </ol>
    <div class="Display">
        <table class="table table-bordered text-center">
            <tbody>
            <tr>
                <td>公告标题</td>
                <td>
                    <input type="text" class="form-control"   placeholder="公告标题" id="title" style="font-size: 12px;">
                </td>
            </tr>
            <tr>
                <td>公告内容</td>
                <td style="text-align: left">
                    <textarea class='form-control' rows='' placeholder='公告内容' id="content" style='resize: none;width: 100%;font-size: 12px;' name='content'></textarea>
                </td>
            </tr>
            <tr>
                <td>起止时间</td>
                <td style="text-align: left">
                    <input  class="control selStartTime" style="cursor:pointer!important;"  type="text" readonly="true" placeholder="请选择开始时间" id="start_dt" />&nbsp;&nbsp;至
                    <input  class="control selEndTime" style="cursor:pointer!important;" type="text" readonly="true"  placeholder="请选择结束时间" id="end_dt" />
                </td>
            </tr>
            <tr>
                <td>公告类型</td>
                <td style="text-align: left">
                 <span class="mr10">
                    <input type="radio" name="noticetable_type"  id="xt" value="1" checked="true" ><label >系统公告</label>
                </span>
                <span class="mr10">
                    <input type="radio" name="noticetable_type"  id="pmd" value="2"><label>跑马灯公告</label>
                </span>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="form-group">
            <div class="col-md-1 col-md-11">
                <button type="button" class="btn btn-success" style="background-color:#c4d703;border-color:#c4d703;" id="save_btn">保存</button>
            </div>
        </div>
    </div>
    <div id="myModalContainer"/>
</div>
</body>
<script>
    //日期显示
    var start = {
        format: 'YYYY-MM-DD hh:mm:ss',
        isinitVal:false,
        ishmsVal:false,
        maxDate: '2099-06-30 23:59:59', //最大日期
        choosefun: function(elem,datas){
            end.minDate = datas; //开始日选好后，重置结束日的最小日期
        }
    };
    var end = {
        format: 'YYYY-MM-DD hh:mm:ss',
        isinitVal:false,
        maxDate: '2099-06-16 23:59:59', //最大日期
        choosefun: function(elem,datas){
            start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    $('.selStartTime').jeDate(start);
    $('.selEndTime').jeDate(end);
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + date.getHours() + seperator2 + date.getMinutes()
                + seperator2 + date.getSeconds();
        return currentdate;
    }
    function initDate(){
        $.jeDate({
            dateCell:"#start_dt",
            isTime:true, //isClear:false,
            minDate: getNowFormatDate()
        });
        $.jeDate({
            dateCell:"#end_dt",
            isTime:true, //isClear:false,
            minDate: getNowFormatDate()
        });

    }

</script>
</html>